<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('用户列表')" />
	<th:block th:include="include :: layout-latest-css" />
</head>
<body class="gray-bg">
		<div class="container-div">
		        <div class="btn-group-sm" id="toolbar" role="group">
		        	<a class="btn btn-success" onclick="$.operate.addTab()">
		                <i class="fa fa-plus"></i> 新增
		            </a>
					<a class="btn btn-danger multiple disabled" onclick="$.operate.batchRemove()">
						<i class="fa fa-remove"></i> 批量删除
					</a>
		        </div>

		        <div class="col-sm-12 select-table table-striped">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
	</div>

	<th:block th:include="include :: footer" />
		<th:block th:include="include :: layout-latest-css" />
	<script th:inline="javascript">
		var prefix = ctx ;
		$(function() {
				var options = {
					url: "/user/getUserList",
					createUrl: prefix + "user/getAddPage",
					updateUrl: prefix + "user/getEditPage/{id}",
					removeUrl: prefix + "user/remove/{id}",
					batchRemoveUrl: prefix + "user/batchRemove",
					editUrl: prefix + "user/getEditPage/{id}",
					// sortName: "createTime",
					// sortOrder: "desc",
					modalName: "用户",
					columns: [{
						checkbox: true
					},
						{
							field: 'sysuserId',
							title: '用户ID'
						},
						{
							field: 'username',
							title: '登录名称',
							sortable: true
						},
						{
							field: 'name',
							title: '用户名称'
						},
						 {
							field: 'mobile',
							title: '手机'
						},
						{
							title: '用户状态',
							align: 'center',
							formatter: function (value, row, index) {
								return statusTools(row);
							}
						},
						  {
                              field: 'createTime',
                              title: '创建时间',
                              sortable: true
                          },
						{
							field: 'lastLoginTime',
							title: '上次登录时间',
							sortable: true
						},
						{
							title: '操作',
							align: 'center',
							formatter: function(value, row, index) {
								var actions = [];
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.sysuserId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
								actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.sysuserId + '\')"><i class="fa fa-remove"></i>删除</a> ');
								actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="resetPwd(\'' + row.sysuserId + '\')"><i class="fa fa-key"></i>重置密码</a> ');
								return actions.join('');
							}
						}]
				};

				$.table.init(options);
		});


		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});

		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});



		/* 用户管理-重置密码 */
		function resetPwd(sysuserId) {
		    var url = prefix + 'user/resetPwdPage/' + sysuserId;
		    $.modal.open("重置密码", url, '800', '300');
		}


		/* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.sysuserId + '\')"></i> ';
    		} else {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.sysuserId + '\')"></i> ';
    		}
		}

		/* 用户管理-停用 */
		function disable(userId) {
			$.modal.confirm("确认要停用用户吗？", function() {

				$.operate.post(prefix + "user/changeStatus", { "sysuserId": userId, "status": 1 });
		    })
		}

		/* 用户管理启用 */
		function enable(userId) {
			$.modal.confirm("确认要启用用户吗？", function() {
				$.operate.post(prefix + "user/changeStatus", { "sysuserId": userId, "status": 0 });
		    })
		}

	</script>
</body>
</html>